package com.cs.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cs.pojo.User;
import com.cs.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private IUserService iUserService;

    @GetMapping()
    public List<User> getAll(){
        return iUserService.list();
    }

    @PostMapping
    public Boolean save(@RequestBody User user){
        return iUserService.save(user);
    }
    @PutMapping
    public Boolean update(@RequestBody User user){
        return iUserService.updateById(user);
    }
    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Integer id){
        return iUserService.removeById(id);
    }

    @GetMapping("/{id}")
    public User getById(@PathVariable Integer id){
        return iUserService.getById(id);
    }

    @GetMapping("/{currentPage}/{pageSize}")
    public IPage<User> getPage(@PathVariable int currentPage,@PathVariable int pageSize){
       return iUserService.getPage(currentPage,pageSize);
    }

}
